package com.company.test30;

import com.sun.corba.se.spi.activation.Server;

import javax.swing.*;
import java.applet.Applet;
import java.awt.*;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

/**
 * Created by v on 16-12-5.
 */
public class Test3002Server extends Applet implements Runnable{
    private JTextArea area=new JTextArea();

    public Test3002Server(){
        setLayout(new BorderLayout());
        add(new JScrollPane(area), BorderLayout.CENTER);
        setSize(500,300);
        Thread thread=new Thread(this);
        thread.start();
    }

    @Override
    public void run() {
        try{
            ServerSocket serverSocket=new ServerSocket(8000);
            Socket socket=serverSocket.accept();

            ObjectInputStream input=new
                    ObjectInputStream(socket.getInputStream());

            StudentAddress address=(StudentAddress)input.readObject();

            area.append(address.getName()+'\n');
            area.append(address.getStreet()+'\n');
            area.append(address.getCity()+'\n');
            area.append(address.getState()+'\n');
            area.append(address.getZip());
        }catch (Exception ex){
            ex.printStackTrace();
        }
    }
}
